from RedisUtil import *
import json
import matplotlib.pyplot as plt
redis = RedisUtil()
fig,ax=plt.subplots()
while 1:
    arr = redis.getArray("192.168.27.36")
    x = []
    y1 = []
    print(str(reversed(arr)))
    for line in reversed(arr):
        print(line)
        obj = json.loads(line.replace("'","\""))
        print(obj["logtime"])
        # 准备数据
        x.append(obj["logtime"])
        y1.append(int(obj["cpu"]))

    ax.cla()
    ax.set_title("cpu")
    ax.set_xlabel("time")
    ax.set_ylabel("cpu")
    ax.set_ylim(0,100)
    ax.grid()
    ax.plot(y1, label='cpu')
    ax.legend(loc='best')

    plt.pause(10)
